<template>
	<page>
		<view>
			<button type='primary' @tap='getContacts'>获取联系人</button>
			<!-- <block v-for="(item,index) in list" :key='index'>
				<view>{{item.displayName}}第一个人</view>
				<block v-for="(subitem,idx) in item.phoneNumbers" :key='idx'>
					<view>{{subitem.value}}第二个人</view>
				</block>
			</block> -->
		</view>
	
		<!-- <view class="header-two">
		     <view>
		      <i class="glyphicon glyphicon-chevron-left" @click="back()"><a href="javascript:back()"></a> </i>
		      <view class="input">
		        <span class="glyphicon glyphicon-search"></span> 
		        <input id="search" type="text" />
		      </view>
		    </view>
		</view> -->
			<view class="header">
				 <view @tap='getContacts'>
				  <p>通讯录</p>
				  <span class="glyphicon glyphicon-plus"></span>
				  <span id="gosearch" class="glyphicon glyphicon-search"></span>
				</view>
		    </view>
		    <view id="letter" ></view>
		    <view class="sort_box-two">
		    
			</view>
			
			
		  <view class="sort_box">
			  
			  
				<view class="sort_list" v-for="(item,index) in list" :key='index'>
				  <view class="num_logo">
					<img src="/static/images/user-center/timg.jpg" alt="">
				  </view>
				  <view class="num_name">
					   <view class="num_name_one">{{item.displayName}} </view>
					   <view class="num_name_two">手机通讯录:{{item.displayName}}</view>
					  </view>
				 
				   <view class="num_submit" v-for="(subitem,idx) in item.phoneNumbers">
						<button type="button" class="btn btn-success" @tap='sendShare' :data-mobile="subitem.value">邀请好友</button>
				   </view>
				</view>
				<view id='mail-list'></view>
				
				
				
				
				
		  </view>
		  
		  
		  
		  <view class="initials">
		    <ul>
		    </ul>
		  </view>  
			
	</page>
</template>

<script>
	
		export default {
			onLoad(){
				// #ifdef APP-PLUS
				this.getContacts();
				// #endif
			},
			data() {
				return {
					list: []
				}
			},
			onShow() {
				uni.setNavigationBarTitle({
						title: '通讯录'
				});
			},
			methods: {
				// #ifdef APP-PLUS
				sendShare:function(e){
					console.log('e的值aa',e);
					let mobile=e.currentTarget.dataset.mobile;
					console.log('mobile的值',mobile);
					// plus.share.sendWithSystem({content:'我最近在使用[同城共享装修],你也来一起玩儿吧!点击链接前往下载',href:mobile}, function(){
					// 	console.log('分享成功');
					// }, function(e){
					// 	console.log('分享失败：'+JSON.stringify(e));
					// });
					var msg = plus.messaging.createMessage(plus.messaging.TYPE_SMS);
						msg.to = [mobile];
						msg.body = '我最近在使用【同城共享装修】,你也来一起玩儿吧!点击链接前往下载 http://www.zxgyzj.com/app-package/1.0.0.apk';
						plus.messaging.sendMessage( msg );
				},
				getContacts: function() {
					var that = this
					// 获取通讯录对象
					plus.contacts.getAddressBook( plus.contacts.ADDRESSBOOK_PHONE, function( addressbook ) {
						uni.showToast({
						    title: '获取通讯录对象成功',
						    duration: 2000
						})
						console.log('获取通讯录对象成功')
						console.log(addressbook)
						// 查找联系人
						addressbook.find(["displayName","phoneNumbers"],function(contacts){
							uni.showToast({
							    title: '获取中，请稍等',
							})
							console.log('获取联系人成功')
							console.log(JSON.stringify(contacts));
							that.list = contacts
						}, function () {
							uni.showToast({
							    title: '获取联系人失败',
							    duration: 2000
							})
						},{multiple:true});
					}, function ( e ) {
						uni.showToast({
						    title: '获取通讯录对象失败:' + e.message,
						    duration: 2000
						})
					});
				},
				// #endif
			}
		}
</script>

<style>
	/*新增的開始*/
	.btn-success {
	    color: #fff;
	    background-color: #5cb85c;
	    border-color: #4cae4c;
	}
	.btn {
	    display: inline-block;
	    padding: 6px 12px;
	    margin-bottom: 0;
	    font-size: 14px;
	    font-weight: 400;
	    line-height: 1.42857143;
	    text-align: center;
	    white-space: nowrap;
	    vertical-align: middle;
	    -ms-touch-action: manipulation;
	    touch-action: manipulation;
	    cursor: pointer;
	    -webkit-user-select: none;
	    -moz-user-select: none;
	    -ms-user-select: none;
	    user-select: none;
	    background-image: none;
	    border: 1px solid transparent;
	    border-radius: 4px;
	}
	
	/*新增的結束*/
	 * {
	    margin: 0;
	    padding: 0;
	}
	  body{
	    font-size:16px;
	  }
	  .header{
	  
	    position: fixed;
	    left: 0;
	    top: 0;
	    z-index: 99;
	    width: 100%;
	    height: 45px;
	    background: #21a4f4;
	  }
	  .header p{
	    margin-left:20px;
	    height: 45px;
	    line-height: 45px;
	    color: #fff;
	    font-size: 18px;
	    display:inline-block;
	  }
	  .header span{
	    color:#fff;
	    margin-right: 20px;
	    float: right;
	    line-height: 45px;
	  }
	  .content{
	    margin-top:45px;
	  }
	  .nav{
	  background-color: #fff;
	  }
	  .header-two{
	  
	    position: fixed;
	    left: 0;
	    top: 0;
	    z-index: 99;
	    width: 100%;
	    height: 45px;
	    background: #21a4f4;
	    
	    
	  }
	  .header-two p{
	    margin-left:20px;
	    height: 45px;
	    line-height: 45px;
	    color: #fff;
	    font-size: 18px;
	    display:inline-block;
	  }
	  .header-two span{
	    color:#fff;
	    margin-left:6px;
	    line-height: 45px;
	  }
	  .header-two i{
	    color:#fff;
	    margin-left: 20px;
	    line-height: 45px;
	  }
	  .header-two input{
	    border:none;
	    
	    width:80%;
	    background-color:transparent;
	  }
	  .sort_box-two{
	    display:block;
	  }
	  .input{
	    border-bottom: 2px #fff solid;
	    display: inline-block;
	    height: 42px;
	    width: calc(100% - 50px);
	  }
	  ul li{list-style: none;}
	a{text-decoration: none;cursor: pointer;}
	html{height: 100%;}
	a,input,img,textarea,span,view{outline: 0;-webkit-tap-highlight-color:rgba(255,0,0,0);}
	 
	#letter{
	    width: 100px;
	    height: 100px;
	    border-radius: 5px;
	    font-size: 75px;
	    color: #555;
	    text-align: center;
	    line-height: 100px;
	    background: rgba(145,145,145,0.6);
	    position: fixed;
	    left: 50%;
	    top: 50%;
	    margin:-50px 0px 0px -50px;
	    z-index: 99;
	    display: none;
	}
	#letter img{
	    width: 50px;
	    height: 50px;
	    float: left;
	    margin:25px 0px 0px 25px;
	}
	[class^="sort_box"]{
	    width: 100%;
	   /* padding-top: 45px; */
	    overflow: hidden;
	    
	}
	[class^="sort_list"]{
	    padding:10px 60px 10px 80px;
	    position: relative;
	    line-height: 50px;
	    border-bottom:1px solid #ddd;
		height:50px;
	}
	 
	[class^="sort_list"] .num_logo{
	    width: 50px;
	    height: 50px;
	    border-radius: 10px;
	    overflow: hidden;
	    position: absolute;
	    left: 20px;
	}
	[class^="sort_list"] .num_logo img{
	    width: 50px;
	    height: 50px;
	}
	/*自己添加的按钮开始*/
	[class^="sort_list"] .num_submit{
	    /*width: 50px;
	    height: 50px;*/
	    border-radius: 5px;
	    overflow: hidden;
	    position: absolute;
	    right: 20px;
	    top:9px;
	}
	[class^="sort_list"] .num_submit button{
	    /*width: 50px;
	    height: 50px;*/
	}
	/*自己添加的按钮结束*/
	[class^="sort_list"] .num_name{
	    color: #000;
		position:absolute;
		top:-5px;
		left: 120px;
	}
	[class^="sort_list"] .num_name_one{
	 	position:absolute;
	 	top:3px;
	 	left: -30px;
		width:360upx;
		overflow:hidden;
	 }
	 [class^="sort_list"] .num_name_two{
	    width:340upx;
	  	position:absolute;
	  	top:23px;
	  	left: -30px;
		overflow:hidden;
	  }
	.sort_letter{
	    height: 30px;
	    line-height: 30px;
	    padding-left: 20px;
	    color:#787878;
	    font-size: 14px;
	    border-bottom:1px solid #ddd;
	}
	.initials{
	    position: fixed;
	    top: 47px;
	    right: 0px;
	    height: 100%;
	    width: 15px;
	    padding-right: 10px;
	    text-align: center;
	    font-size: 12px;
	    z-index: 99;
	    background: rgba(145,145,145,0);
	}
	.initials li img{
	    width: 14px;
	}
</style>
